﻿
/*============== simpleIRC - http://matthias.van-eeghem.com/ ==============*
 *                                                                         *
 *  File: Sounds.cs                                                      *
 *  Project: simpleIRC                                                     *
 *  Author(s): Matthias Van Eeghem <matthias@van-eeghem.com>               *
 *                                                                         *
 * ========================================================================*
 *                                                                         *
 *  This program is free software: you can redistribute it and/or modify   *
 *  it under the terms of the GNU General Public License as published by   *
 *  the Free Software Foundation, either version 3 of the License, or      *
 *  (at your option) any later version.                                    *
 *                                                                         *
 *  This program is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *  GNU General Public License for more details.                           *
 *                                                                         *
 *  You should have received a copy of the GNU General Public License      *
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 *                                                                         *
===========================================================================*/

using System.Media;

namespace simpleIRC.UI
{
    /// <summary>
    /// The sounds class, this class plays sound files for the client.
    /// </summary>

    public static class Sounds
    {
        // All possible sound types:
        /// <summary>
        /// Plays Sounds/Bass.wav
        /// </summary>
        public static int BASS_SOUND = 0;
        /// <summary>
        /// Plays Sounds/Ping.wav
        /// </summary>
        public static int PING_SOUND = 1;
        /// <summary>
        /// Plays Sounds/Pong.wav
        /// </summary>
        public static int PONG_SOUND = 2;
        /// <summary>
        /// Plays Sounds/Synth.wav
        /// </summary>
        public static int SYNTH_SOUND = 3;

        // This variable holds the object to the SoundPlayer
        private static SoundPlayer SoundPlayer;

        /// <summary>
        /// This method plays a sound for the client
        /// </summary>
        /// <param name="soundType">The sound type, this can be any of the static ints on the top of the class</param>

        public static void Play(int soundType)
        {
            // We initialise this to a valid song incase no valid sound type was passed on as parameter
            string FileName = "Bass.wav";

            // Change the filename from the sound type
            if (soundType == BASS_SOUND) FileName = "Bass.wav";
            if (soundType == PING_SOUND) FileName = "Ping.wav";
            if (soundType == PONG_SOUND) FileName = "Pong.wav";
            if (soundType == SYNTH_SOUND) FileName = "Synth.wav";

            StopAllSounds();

            SoundPlayer = new SoundPlayer("Sounds/" + FileName);
            SoundPlayer.Play();
        }

        /// <summary>
        /// This method stops any sounds already playing for the client.
        /// </summary>

        private static void StopAllSounds()
        {
            if(SoundPlayer != null)
                SoundPlayer.Stop();
        }
    }
}
